/**
 * 
 */
package action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.json.JSONObject;

import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionContext;

import pojo.Alarm;
import service.UserService;
import service.impl.UserServiceImpl;

/**
 * @author chenguanshen
 *2016年7月23日
 */
public class PageAction {
	private Alarm alarm = new Alarm();
	private UserService userService =new UserServiceImpl();
	private String page;//当前页码
	private String rows;//每页记录数
	static Logger log = Logger.getLogger(PageAction.class); 
	

	//查询所有报警信息
	public void getAllAlarm() throws Exception {  
          
        List list = userService.getAlarmList(page, rows); 
        this.toBeJson(list,userService.getAlarmTotal());  

    }  
	//转化为Json格式  
    public void toBeJson(List list,int total) throws Exception{  
         HttpServletResponse response = ServletActionContext.getResponse();  
         HttpServletRequest request = ServletActionContext.getRequest();  

 		Map map=new HashMap();
 		map.put("total", total);
 		map.put("rows", list);
 		response.setCharacterEncoding("utf-8");
 		String jsonString = JSON.toJSONString(map);
 		 response.getWriter().write(jsonString);
    }  
      
	
	
	
	
	
	
	public Alarm getAlarm() {
		return alarm;
	}

	public void setAlarm(Alarm alarm) {
		this.alarm = alarm;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	public String getPage() {
		return page;
	}
	public void setPage(String page) {
		this.page = page;
	}
	public String getRows() {
		return rows;
	}
	public void setRows(String rows) {
		this.rows = rows;
	}

}
